package com.android.common.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class EnvDBHelper {

    private Context mContext;

    private static EnvDBHelper mEnvDBHelper;

    public static EnvDBHelper getInstance(Context context){
        if (null == mEnvDBHelper)
            mEnvDBHelper = new EnvDBHelper(context);
        return mEnvDBHelper;
    }
    private EnvDBHelper(Context context) {
        mContext = context;
    }

    public int update(ContentValues values) {
        return CommonDBOperation.getInstance(mContext).update(DBConfig.ENV_TABLE_NAME,values,null,null);
    }

    public String queryServerApiAddress() {
        Cursor cursor = CommonDBOperation.getInstance(mContext).query(DBConfig.ENV_TABLE_NAME,new String[]{Columns.ENV_SERVER_API_ADDRESS},null,null,null,null,null);
        String result = "";
        if (cursor != null && cursor.moveToFirst()) {
            do {
                result = cursor.getString(cursor.getColumnIndexOrThrow(Columns.ENV_SERVER_API_ADDRESS));
            } while (cursor.moveToNext());
            cursor.close();
        }
        return result;
    }

    public String queryH5Address() {
        Cursor cursor = CommonDBOperation.getInstance(mContext).query(DBConfig.ENV_TABLE_NAME,new String[]{Columns.ENV_H5_ADDRESS},null,null,null,null,null);
        String result = "";
        if (cursor != null && cursor.moveToFirst()) {
            do {
                result = cursor.getString(cursor.getColumnIndexOrThrow(Columns.ENV_H5_ADDRESS));
            } while (cursor.moveToNext());
            cursor.close();
        }
        return result;
    }

    public String queryOtherAddress() {
        Cursor cursor = CommonDBOperation.getInstance(mContext).query(DBConfig.ENV_TABLE_NAME,new String[]{Columns.ENV_OTHER_ADDRESS},null,null,null,null,null);
        String result = "";
        if (cursor != null && cursor.moveToFirst()) {
            do {
                result = cursor.getString(cursor.getColumnIndexOrThrow(Columns.ENV_OTHER_ADDRESS));
            } while (cursor.moveToNext());
            cursor.close();
        }
        return result;
    }

}
